home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_5.lha
/
5_5
/
5_5cOb.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
1KB
|
68 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
ain(int, char)
char *s = "123/4+123*4-3";
expr x(s);
x.print();
cout << "\n";
return 0;
/ print the expression tree
tatic char *spaces(int num)
return form("%.*s", num * 3, " ");
oid tree::print(int level)
if (this)
switch (this->type)
{
case PLUS:
case DIV:
case MUL:
cout << spaces(level) << chr(this->type) << "\n";
this->left->print(level + 1);
this->right->print(level + 1);
return;
case MINUS:
cout << spaces(level) << chr(this->type) << "\n";
if (this->right)
{
this->left->print(level + 1);
this->right->print(level + 1);
}
else
this->left->print(level + 1);
return;
case NUMBER:
cout << spaces(level) << "# " << this->value << "\n";
return;
case LP:
cout << spaces(level) << chr(this->type) << "\n";
this->left->print(level + 1);
return;
case RP:
case END:
default:
cout << spaces(level) << chr(this->type) << "\n";
error("invalid type within tree");
break;
}
else
error("NULL node found");
return;
oid expr::eprint()
head->print(0); }